<?php
//功能：quality控制器
namespace Home\Controller;
use Think\Controller;
use Think\Upload;
class VINController extends Controller{
	/**
	 * 显示VIN码界面
	 */
	public function index(){
	     $this->display();
	}

	/**
	 * 显示VIN码计算界面
	 */
	public function Cal(){
	     $this->display();
	}
/**
 * [read VIN数据]
 * @return [json] [返回json格式的easyui-datagrid数据]
 */
	public function read(){
		$vin=M("vin");
	 
	    $pagenum=isset($_POST['page']) ? intval($_POST['page']) : 1;
	    $rowsnum=isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    
	    /* 搜索条件 start*/
	    $map=array();	   
	    // 获取表所有字段名
	    $Fields=$vin->getDbFields();
	    foreach ($Fields as $key => $value) {
	    	if(isset($_POST[$value])){
	    		$datas=$_POST[$value];
	    		   $map[$value]=array('LIKE',array("%".$datas."%"));
	    	}	  
	    }  


// $map['creatdate'] = array(array('egt',strtotime($creatdates)),array('elt',strtotime($creatdatee)));

	    // 将map写入session
	    session('map_vin',$map);
	    /* 搜索条件 end*/
	    $vinlist=$vin->where($map)->limit(($pagenum-1)*$rowsnum.','.$rowsnum)->order('ids desc')->select();
	 
	    $total=$vin->where($map)->count();
	    if ($total==0){
	        $json='{"total":'.$total.',"rows":[]}';
	        echo $json;
	    }else{
	        $json='{"total":'.$total.',"rows":'.json_encode($vinlist).'}';//重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
	        echo $json;
	    }
	
	}

    /**
     * 解锁vin上传图片
     */
    public function unlockvinpic()
    {
        $mes=M('mes');
        $map['id']=$_POST['id'];
        $data['vinpic']='';
        $re=$mes->where($map)->save($data);
        if($re){
            echo json_encode(array("status" => 1, "massage" => '上传VIN码打印位置图片成功！'));
        }else{
            echo json_encode(array("status" => 0, "massage" => '上传VIN码打印位置图片失败！'));
        }
}

public function viewprinter(){
	$rows=$_GET['rows'];
	$this->display();
}
 /**
  * [import 导出常规数据]
  * @return [type] [description]
  */
// public function daochu1(){
// 	$data['data']=$_POST;
// 	$data['status']=1;


// 	$data=$_POST['rows'];

// 	echo json_encode($data);
// }
/**
  * [out 导出]
  * @return [type] [服务记录导出，带筛选]
  */
 public function daochu11(){
 
 	
 	//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
 	import("Org.Util.PHPExcel");
 	import("Org.Util.PHPExcel.Writer.Excel5");
 	import("Org.Util.PHPExcel.IOFactory.php");
 	// 创建一个处理对象实例
 	$objExcel = new \PHPExcel();
 	// 创建文件格式写入对象实例, uncomment
 	$objWriter = new \PHPExcel_Writer_Excel5($objExcel);
 	$objProps = $objExcel->getProperties();
 	$objProps->setCreator("工艺信息管理平台");
 	$objProps->setLastModifiedBy("工艺科 范建鹏");
 	$objProps->setTitle("越野车装配厂 工艺信息记录");
 	$objProps->setSubject("工艺信息记录");
 	$objProps->setDescription("越野车装配厂 工艺信息记录");
 	$objProps->setKeywords("越野车装配厂 工艺信息记录");
 	$objProps->setCategory("装配问题记录");
 	//*************************************
 	//设置当前的sheet索引，用于后续的内容操作。
 	//一般只有在使用多个sheet的时候才需要显示调用。
 	//缺省情况下，PHPExcel会自动创建第一个sheet被设置SheetIndex=0
 	$objExcel->setActiveSheetIndex(0);
 	$objActSheet = $objExcel->getActiveSheet();
 	//设置当前活动sheet的名称
 	$date = date("Y-m-d",time());
 	$objActSheet->setTitle('装配问题记录'.$date);
 	//设置宽度，这个值和EXCEL里的不同，不知道是什么单位，略小于EXCEL中的宽度
 	$objActSheet->getColumnDimension('A')->setWidth(3);
 	$objActSheet->getColumnDimension('B')->setWidth(13);
 	$objActSheet->getColumnDimension('C')->setWidth(20);
 	$objActSheet->getColumnDimension('D')->setWidth(13);
 	$objActSheet->getColumnDimension('E')->setWidth(15);
 	$objActSheet->getColumnDimension('F')->setWidth(10);
 	$objActSheet->getColumnDimension('G')->setWidth(15);

 	$objActSheet->getRowDimension('2')->setRowHeight(40);
 	$objActSheet->getRowDimension('3')->setRowHeight(40);
 	$objActSheet->getRowDimension('4')->setRowHeight(40);
 	$objActSheet->getRowDimension('5')->setRowHeight(40);
 	$objActSheet->getRowDimension('6')->setRowHeight(40);
 	$objActSheet->getRowDimension('7')->setRowHeight(110);
 	$objActSheet->getRowDimension('8')->setRowHeight(110);
 	$objActSheet->getRowDimension('9')->setRowHeight(110);
	$objActSheet->getRowDimension('10')->setRowHeight(110);
 	//设置单元格的值
 	$objActSheet->setCellValue('B2', '越野车装配厂装配问题记录');
	$objActSheet->setCellValue('B11', '越野车装配厂');
	$objActSheet->setCellValue('B12', 'SOLVE工艺信息管理系统    '.date("Y-m-d",time()));
	$objActSheet->getStyle('B11')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
	$objActSheet->getStyle('B12')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
 	//合并单元格
 	$objActSheet->mergeCells('B2:G2');
 	$objStyleA1 = $objActSheet->getStyle('B2');
 	$objStyleA1->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
 	$objFontA1 = $objStyleA1->getFont();
 	$objFontA1->setName('宋体');
 	$objFontA1->setSize(18);
 	$objFontA1->setBold(true);

 	$objActSheet->setCellValue('B3', '创建日期 ');
 	$objActSheet->setCellValue('B4', '车  型 ');
 	$objActSheet->setCellValue('B5', '计生号 ');
 	$objActSheet->setCellValue('B6', '问题类别');
 	$objActSheet->setCellValue('B7', '问题描述');
 	$objActSheet->setCellValue('B8', '现场处理');
 	$objActSheet->setCellValue('B9', '图片文件');
 	$objActSheet->setCellValue('B10', '回复');


 	$objActSheet->setCellValue('D3', '车间');
 	$objActSheet->setCellValue('F3', '班次');
 	$objActSheet->setCellValue('D4', '车型平台');
 	$objActSheet->setCellValue('F4', '车辆类型');
 	$objActSheet->setCellValue('D5', '流水号');
 	$objActSheet->setCellValue('F5', '协议号');

 	//设置合并

 	$objActSheet->mergeCells('C7:G7');
 	$objActSheet->mergeCells('C8:G8');
 	$objActSheet->mergeCells('C9:G9');
 	$objActSheet->mergeCells('C10:G10');
 	$objActSheet->mergeCells('B11:G11');
 	$objActSheet->mergeCells('B12:G12');
 	$objActSheet->mergeCells('D6:G6');





 	
 	//设置对齐
 	$objActSheet->getStyle('C7')->getAlignment()->setWrapText(true);//自动换行
 	$objActSheet->getStyle('C8')->getAlignment()->setWrapText(true);
 	$objActSheet->getStyle('C10')->getAlignment()->setWrapText(true);
 	$objActSheet->getStyle('A2:I2')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 	//加粗
 	$objActSheet->getStyle('B3:B9')->getFont()->setBold(true);
 	$objActSheet->getStyle('C5:G5')->getFont()->setBold(true);
 	$objActSheet->getStyle('F3:F4')->getFont()->setBold(true);
 	$objActSheet->getStyle('D3')->getFont()->setBold(true);
	$objActSheet->getStyle('B10')->getFont()->setBold(true);
 	
 	
 	// $objStyleA2 = $objActSheet->getStyle('C5:G5');
 	// $objStyleA2->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
 	
 	//从数据库取值循环输出

 	
 	
 	$styleArray = array(
 			'borders' => array(
 					'allborders' => array(
 							//'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
 							'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
 							//'color' => array('argb' => 'FFFF0000'),
 					),
 			),
 	);
 	$objActSheet->getStyle('B3:G10')->applyFromArray($styleArray);//这里就是画出从单元格A5到
 	
 	
 	$outputFileName =iconv("utf-8", "gb2312","工艺信息记录导出 ".$date).".xls";
	
 	
 	header("Pragma: public");
 	header('Expires:0');
 	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 	header("Content-Type:application/force-download");
 	Header('content-Type:application/vnd.ms-excel;charset=utf-8');
 	Header("Content-type: application/octet-stream;charset=utf-8");
 	header("Content-Type:application/octet-stream");
 	header("Content-Type:application/download");
 	header("Content-Disposition: attachment;filename=$outputFileName");
 	header("Content-Transfer-Encoding:binary");
 	
 	$objWriter->save('php://output');
 	
 	echo $page .$pagesize;
 	exit;
 }
 

	 //导入数据
 /**
  * [import MES数据导入]
  * @return [type] [description]
  */
    public function  import(){
    	$targetFolder = '/solve/Public/uploadtemp/vin'; //上传的目标路径
    	if (!empty($_FILES)) {
    		$tempFile = $_FILES['file']['tmp_name'];
    		$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    	
    		$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file']['name'];
    		// Validate the file type
    		$fileTypes = array('xls'); // File extensions
    		$fileParts = pathinfo($_FILES['file']['name']);
    	
    		//查看文件的名字符串的编码方式
    		$encode = mb_detect_encoding($targetFile, array("UTF-8","GBK","ASCII","GB2312"));

    	
    		if ($encode == "UTF-8"){
    			$targetFile = iconv("UTF-8","GBK",$targetFile);
    		}
    	
    	
    		if (in_array($fileParts['extension'],$fileTypes)) {
    			move_uploaded_file($tempFile,$targetFile);
    			// echo md5($_FILES['file']['name']);
    			//导入
    			//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
    			import("Org.Util.PHPExcel");
    			import("Org.Util.PHPExcel.Writer.Excel5");
    			import("Org.Util.PHPExcel.IOFactory.php");
    			import("Org.Util.PHPExcel.Reader.Excel5");
    			
    			// 创建一个处理对象实例
    			$PHPExcel = new \PHPExcel();
    			
    			$PHPReader=new \PHPExcel_Reader_Excel5();
    			
    			//载入文件
    			
    			$PHPExcel=$PHPReader->load($targetFile);
    			
    			//获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推
    			
    			$currentSheet=$PHPExcel->getSheet(0);
    			
    			//获取总列数
    			
    			$allColumn=$currentSheet->getHighestColumn();
    			
    			//获取总行数
    			
    			$allRow=$currentSheet->getHighestRow();
//     			$clu=array('A','B','C','D','E','F','G','L','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF');
    			//循环获取表中的数据，$currentRow表示当前行，从哪行开始读取数据，索引值从0开始
    			$ColumnN= \PHPExcel_Cell::columnIndexFromString($allColumn);
    			
    			// $Mes = M("Mes");
    			// $ggd->where('1')->delete();
    			for($currentRow=2;$currentRow<=$allRow;$currentRow++){

    		
    				
    				for($currentColumn=0;$currentColumn<=$ColumnN;$currentColumn++){
    				
    					//数据坐标
    					$colum = \PHPExcel_Cell::stringFromColumnIndex($currentColumn);
    					
    					$address=$colum.$currentRow;
    					 
    					//读取到的数据，保存到数组$arr中
    					 $cell=$currentSheet->getCell($address)->getValue();
    					if(is_object($cell))  
    						$cell= $cell->__toString();


    					$arr[$currentRow][$currentColumn]=$cell;
    					 
    				}
    			
    			}

    	 // var_dump($arr);
    			$mes=M('mes');
    			for($i=2;$i<count($arr)+2;$i++){


    				$data['cx'] = $arr[$i][0];
					$data['vin8'] = $arr[$i][1];
					$data['lshqj'] = $arr[$i][2];
                    $data['rwh'] = $arr[$i][3];
                    $data['bz'] = '';

                    $map2['zwh']=array('LIKE',array("%".$data['rwh']."%"));
                    $lsh2=$mes->where($map2)->find();
                    if($lsh2){
                        $data['lsh2']  =$lsh2['lshqj'];
                        $data['wlbm']  =$lsh2['wlbm'];
                    }else{
                        $data['lsh2']  ='';
                    }

//				用任务号


					$datas[]=	$data;				
    				   					
    			}

    			// 如果导出成功，返回json数据，不然显示错误信息
		$n=count($datas);

    	if($n>0){
    		$result[total]=$n;
    		$result[rows]=$datas;
    		echo json_encode(array("status" => 1,"data" =>$result));
    		// echo json_encode(array("status" => 1,"data" =>"成功导入全部".$n."条数据。"));
    	}else{
    		echo json_encode(array("status" => 0,"data" =>"没有数据导入"));
    	}
// $result=$Mes->addAll($datas);
    	
    		} else {

    			echo json_encode(array("status" => 0,"data" =>'您好，文件类型不允许！'));
    		}
    	}
    }

	

	public function edit(){
		$zds=M("zds");
		$data=$zds->create();
		$id=$_POST['id'];
		$data['gw']=implode(',', $data['gw']);
		$data['date'] = date("Y/m/d");
		if($_POST['id']){
			$map['id'] = $id;
		
			if($_FILES['url']['size']>0){
				// 如果有上传
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728000 ;// 设置附件上传大小
				$upload->exts      =     array('pdf');// 设置附件上传类型
				$upload->rootPath      =  './Public/'; //保存根路径
				$upload->savePath =  '/upload/Zds/';// 设置附件上传目录
				// $upload->saveName = '';//保持原文件名
				$info =  $upload->upload();	
				if(!$info) {// 上传错误提示错误信息 
	        		echo json_encode(array("status" => 0,"data" =>$upload->getError())); 
			    }else{
			    	$data['url'] = $info['url']['savepath'].$info['url']['savename'];

	        		$result = $zds->where($map)->save($data);
	        		 if($result){            
	             		echo json_encode(array("status" => 1,"data" =>'修改作业指导书成功！')); 
			        }else{
			            echo json_encode(array("status" => 0,"data" =>'修改作业指导书失败1！')); 
			            // echo json_encode(array("status" => 0,"data" =>'修改作业指导书失败！')); 
			        }
			    }
			}else{
		// 没有上传文件时	
			    $result = $zds->where($map)->save($data);
			    if($result){            
		             echo json_encode(array("status" => 1,"data" =>'修改作业指导书成功！')); 
		        }else{
		            echo json_encode(array("status" => 0,"data" =>'修改作业指导书失败1！')); 
		        }	
			}

		}else{
			 echo json_encode(array("status" => 0,"data" =>'没有选择作业指导书！')); 
		}
   
}


public function downZds(){
	if(IS_POST){
	


		$url='D:/xampp/htdocs'.__ROOT__.'/Public'.$_POST['url'];
		// import('Org.Net.Http');

		// Http::download($url,'download');

		$http = new \Org\Net\Http;

		$http->download($url,'download');

	}else{
		echo json_encode(array("status" =>0  ,"data" =>'非法请求！')); 
	}
	

	

}


public function sessionVIN(){
	if($_POST){
		session('daochu1',$_POST);
		echo json_encode(array("status" =>1  ,"data" =>'成功')); 
	}else{
		echo json_encode(array("status" =>0  ,"data" =>'失败')); 
	}
	
}

// 上传VIN码
public function updateVin(){
	$data=$_POST['rows'];
 	// $data=$data['rows'];
 	$vin=M('vin');
 	$numOK=0;
 	$numF=0;
 	$mes="";
 	foreach ($data as $r) {
 		// 判断此流水号VIN码是否已经导入
 		// 截取流水号
 		$r['lsh']=substr($r['vin'],9);
 		$map['lsh']=$r['lsh'];
 		$count=$vin->where($map)->count();
 		if($count>0){
 			$numF=$numF+1;
 			$mes=$mes.$r['lsh'].'、';
 		}else{
 			// 将装配计划号、计生号匹配进VIN码数据
 			$map_mes['lsh']=array('LIKE',array("%".$r['lsh']."%"));
 			$data=M('mes')->where($map_mes)->find();
 			if($data){
 				$r['jsh']=$data['sjjhh'];
 				$r['zpjh']=$data['jhh'];
 			}else{
 				$r['jsh']='';
 				$r['zpjh']='';
 			}
 			$vin->add($r);
 			$numOK=$numOK+1;
 		}
 		


 	}
 	if($numF>0){
 			$mes="导入".$numOk."项,".$numF."项没有导入，因为流水号".$mes."已经导入";
 			echo json_encode(array("status" =>1  ,"data" =>$mes)); 
 		}else{
 			$mes="成功导入全部".$numOk."项。";
 			echo json_encode(array("status" =>1  ,"data" =>$mes)); 
 		}



}
//导出普通格式
public function daochu1(){
 	 $data=session(daochu1);
 	 $data=$data['rows'];
 	// if(!$_POST)
 	// 	echo json_encode(array("status" => 0,"data" =>"导出失败"));
 	
 	//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
 	import("Org.Util.PHPExcel");
 	import("Org.Util.PHPExcel.Writer.Excel5");
 	import("Org.Util.PHPExcel.IOFactory.php");

 	// 创建一个处理对象实例	
 	$objExcel = new \PHPExcel();
 	// 创建文件格式写入对象实例, uncomment
 	$objWriter = new \PHPExcel_Writer_Excel5($objExcel);
 	$objProps = $objExcel->getProperties();       

 	$objProps->setCreator("工艺信息管理平台");
 	$objProps->setLastModifiedBy("工艺科 范建鹏");
 	$objProps->setTitle("越野车装配厂 VIN码导出：Excel");
 	$objProps->setSubject("VIN码");
 	$objProps->setDescription("越野车装配厂 VIN码导出");
 	$objProps->setKeywords("越野车装配厂 VIN码");
 	$objProps->setCategory("VIN码");
 	$objRichText = new \PHPExcel_RichText(); 



$objRichText->createText('    '); 
$objPayable0=$objRichText->createTextRun('  根据陕西汽车集团有限责任公司车辆识别代码（VIN）编制规则（SQ 101101-2013）和国家工信部车辆生产企业及产品公告，编制 '); 
$objPayable0->getFont()->setSize(16);
$objPayable0->getFont()->setName('宋体');
 
$objPayable1 = $objRichText->createTextRun(date("Y").'-装配-0XXX'); 
$objPayable1->getFont()->setBold(true); 
// $objPayable1->getFont()->setItalic(true); 
$objPayable1->getFont()->setColor( new \PHPExcel_Style_Color( \PHPExcel_Style_Color::COLOR_RED ) ); 
$objPayable1->getFont()->setSize(16);
$objPayable1->getFont()->setName('宋体');

$objPayable3=$objRichText->createTextRun('东郊部分）车辆识别代码（VIN）如下：'); 
$objPayable3->getFont()->setSize(16);
$objPayable3->getFont()->setName('宋体');

$objRichText->createText(' '); 



// $objPayable->getFont()->setName('宋体');
// $objPayable->getFont()->setSize(16);
// $objPayable1->getFont()->setName('宋体');
// $objPayable1->getFont()->setSize(16);



 	//*************************************
 	//设置当前的sheet索引，用于后续的内容操作。
 	//一般只有在使用多个sheet的时候才需要显示调用。
 	//缺省情况下，PHPExcel会自动创建第一个sheet被设置SheetIndex=0
 	$objExcel->setActiveSheetIndex(0);
 	$objActSheet = $objExcel->getActiveSheet();
 	//设置当前活动sheet的名称
 	$date = date("Y-m-d",time());
 	$objActSheet->setTitle('VIN码'.$date);
 	
 	//*************************************
 	//
 	//设置宽度，这个值和EXCEL里的不同，不知道是什么单位，略小于EXCEL中的宽度
 	$objActSheet->getColumnDimension('A')->setWidth(12);
 	$objActSheet->getColumnDimension('B')->setWidth(42);
 	$objActSheet->getColumnDimension('C')->setWidth(12);
 	$objActSheet->getColumnDimension('D')->setWidth(42);




 $objActSheet->getStyle('A')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
 $objActSheet->getStyle('B')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
 $objActSheet->getStyle('C')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
 $objActSheet->getStyle('D')->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);

 	//设置单元格的值
 	$objActSheet->setCellValue('A1', '通知');
 	//合并单元格
 	$objActSheet->mergeCells('A1:D1');
 	$objStyleA1 = $objActSheet->getStyle('A1');
 	$objStyleA1->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
 	$objFontA1 = $objStyleA1->getFont();
 	$objFontA1->setName('黑体');
 	$objFontA1->setSize(22);
 	$objFontA1->setBold(true); 
 	$objActSheet->setCellValue('A2', $objRichText);
 	$objActSheet->mergeCells('A2:D2');

 	$objStyleA2 = $objActSheet->getStyle('A2:D2');
 	$objActSheet->getRowDimension('2')->setRowHeight(75.75);
 	$objStyleA2->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);


 	$objFontA2 = $objStyleA2->getFont();
 	$objFontA2->setName('宋体');
 	$objFontA2->setSize(16);
 	$objActSheet->getStyle('A2')->getAlignment()->setWrapText(true);//自动换行

 	$objActSheet->setCellValue('A3', '流水号');
 	$objActSheet->setCellValue('B3', 'VIN码/车型/数量');
 	$objActSheet->setCellValue('C3', '流水号');
 	$objActSheet->setCellValue('D3', 'VIN码/车型/数量 ');
 	$objActSheet->getStyle('A3')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 	$objActSheet->getStyle('D3')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);


$count=count($data);

 	for($i=0;$i<$count;$i++){
 		$n=$i+4;

$objActSheet->setCellValueExplicit('A'.$n,$data[$i][lsh1],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('B'.$n,$data[$i][vin1],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('C'.$n,$data[$i][lsh2],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('D'.$n,$data[$i][vin2],\PHPExcel_Cell_DataType::TYPE_STRING);

 	}

$objActSheet->getStyle('A3:D'.($count+3))->getFont()-> setSize(17);

$objActSheet->getStyle('A3:D'.($count+3))->getFont()->setName('宋体');

	 $styleArray = array(
 	 		'borders' => array(
 	 				'allborders' => array(
 	 						//'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
 	 						'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
 	 						//'color' => array('argb' => 'FFFF0000'),
 	 				),
 	 		),
 	 );
 	$objActSheet->getStyle('A1:D'.$n)->applyFromArray($styleArray);//这里就是画出从单元格A5到 


 	 $n=$count+5;
 	
 	$footer="编制：范建鹏                            审批：王晓辉                    批准：何文军";

 	// $objActSheet->setCellValue('A'.$n, 'SOLVE工艺信息管理系统  导出日期：'.date("Y-m-d H:i:s"));
 	$objActSheet->setCellValue('A'.$n, $footer);
 	$objActSheet->mergeCells('A'.$n.':D'.$n);
 	// $objActSheet->getStyle('A'.$n)->getFont()->setBold(true);
 	$objActSheet->getStyle('A'.$n)->getFont()-> setSize(12);
 	$objActSheet->getStyle('A'.$n)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 	// $objActSheet->getStyle('A'.$n.':D'.$n)->applyFromArray($styleArray);//


$objActSheet->setCellValue('A'.($n+1), ' 越野车装配厂技术部');
 	$objActSheet->mergeCells('A'.($n+1).':D'.($n+1));
 	// $objActSheet->getStyle('A'.$n)->getFont()->setBold(true);
 	$objActSheet->getStyle('A'.($n+1))->getFont()-> setSize(12);
 	$objActSheet->getStyle('A'.($n+1))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);




 	$objRichText1 = new \PHPExcel_RichText(); 



$objRichText1->createText(' '); 
$objPayable3=$objRichText1->createTextRun(date("Y-m-d")); 
$objPayable3->getFont()->setSize(12);
$objPayable3->getFont()->setName('宋体');
$objPayable3->getFont()->setColor( new \PHPExcel_Style_Color( \PHPExcel_Style_Color::COLOR_RED ) ); 

$objActSheet->setCellValue('A'.($n+2), $objRichText1);
 	$objActSheet->mergeCells('A'.($n+2).':D'.($n+2));
 	// $objActSheet->getStyle('A'.$n)->getFont()->setBold(true);
 	$objActSheet->getStyle('A'.($n+2))->getFont()-> setSize(12);
 	$objActSheet->getStyle('A'.($n+2))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);


 	// $objActSheet->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
 	// $objActSheet->getStyle('A2:P'.$n)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
 	// $objActSheet->getStyle('A1:P1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
 

 
 	

 
 $outputFileName =iconv("utf-8", "gb2312","VIN码导出(Excel格式)  ".$date).".xls";

 	header("Pragma: public");
 	header('Expires:0');





 	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 	header("Content-Type:application/force-download");
    Header('content-Type:application/vnd.ms-excel;charset=utf-8');
 	header("Content-Type:application/octet-stream");
 	header("Content-Type:application/download");
 	header("Content-Disposition: attachment;filename=$outputFileName");
 	header("Content-Transfer-Encoding:binary");

 	$objWriter->save('php://output');
 	
 	// echo $page .$pagesize;
 	exit;
 }	
//导出MES格式
public function daochu2(){
 	 $data=session(daochu1);
 	 $data=$data['rows'];
 	// if(!$_POST)
 	// 	echo json_encode(array("status" => 0,"data" =>"导出失败"));
 	
 	//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
 	import("Org.Util.PHPExcel");
 	import("Org.Util.PHPExcel.Writer.Excel5");
 	import("Org.Util.PHPExcel.IOFactory.php");

 	// 创建一个处理对象实例	
 	$objExcel = new \PHPExcel();
 	// 创建文件格式写入对象实例, uncomment
 	$objWriter = new \PHPExcel_Writer_Excel5($objExcel);
 	$objProps = $objExcel->getProperties();       

 	$objProps->setCreator("工艺信息管理平台");
 	$objProps->setLastModifiedBy("工艺科 范建鹏");
 	$objProps->setTitle("越野车装配厂 VIN码导出：Excel");
 	$objProps->setSubject("VIN码");
 	$objProps->setDescription("越野车装配厂 VIN码导出");
 	$objProps->setKeywords("越野车装配厂 VIN码");
 	$objProps->setCategory("VIN码");
 	$objRichText = new \PHPExcel_RichText(); 




 	$objExcel->setActiveSheetIndex(0);
 	$objActSheet = $objExcel->getActiveSheet();
 	//设置当前活动sheet的名称
 	$date = date("Y-m-d",time());
 	$objActSheet->setTitle('VIN码'.$date);
 	
 	//*************************************
 	//
 	//设置宽度，这个值和EXCEL里的不同，不知道是什么单位，略小于EXCEL中的宽度
 	$objActSheet->getColumnDimension('A')->setWidth(22);
 	$objActSheet->getColumnDimension('B')->setWidth(14);
 	$objActSheet->getColumnDimension('C')->setWidth(6);





 	$objActSheet->setCellValue('A1', 'VIN码');
 	$objActSheet->setCellValue('B1', '整车流水号');
 	$objActSheet->setCellValue('C1', '备注');


 	$objStyleA = $objActSheet->getStyle('A1:C1')->getFont();
 	$objStyleA->setName('宋体');
 	$objStyleA->setSize(11);



 

$count=count($data);
$objStyleB = $objActSheet->getStyle('A2:C'.($count+2))->getFont();
$objStyleB->setName('宋体');
$objStyleB->setSize(12);




 	for($i=0;$i<$count;$i++){
 		$n=$i+2;

 		$vin=$data[$i][vin];
 		$lsh=substr($vin,9);

$objActSheet->setCellValueExplicit('A'.$n,$vin,\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('B'.$n,$lsh,\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('C'.$n,'DJ',\PHPExcel_Cell_DataType::TYPE_STRING);






 	}

 

 	 $styleArray = array(
 	 		'borders' => array(
 	 				'allborders' => array(
 	 						//'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
 	 						'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
 	 						//'color' => array('argb' => 'FFFF0000'),
 	 				),
 	 		),
 	 );
 	$objActSheet->getStyle('A1:C'.$n)->applyFromArray($styleArray);//这里就是画出从单元格A5到 
 	

 
 $outputFileName =iconv("utf-8", "gb2312","VIN码导出(MES格式)  ".$date).".xls";

 	header("Pragma: public");
 	header('Expires:0');





 	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 	header("Content-Type:application/force-download");
    Header('content-Type:application/vnd.ms-excel;charset=utf-8');
 	header("Content-Type:application/octet-stream");
 	header("Content-Type:application/download");
 	header("Content-Disposition: attachment;filename=$outputFileName");
 	header("Content-Transfer-Encoding:binary");

 	$objWriter->save('php://output');
 	
 	// echo $page .$pagesize;
 	exit;
 }	
 //导出全部格式
public function daochu3(){
 	 $data=session(daochu1);
 	 $data=$data['rows'];
 	// if(!$_POST)
 	// 	echo json_encode(array("status" => 0,"data" =>"导出失败"));
 	
 	//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
 	import("Org.Util.PHPExcel");
 	import("Org.Util.PHPExcel.Writer.Excel5");
 	import("Org.Util.PHPExcel.IOFactory.php");

 	// 创建一个处理对象实例	
 	$objExcel = new \PHPExcel();
 	// 创建文件格式写入对象实例, uncomment
 	$objWriter = new \PHPExcel_Writer_Excel5($objExcel);
 	$objProps = $objExcel->getProperties();       

 	$objProps->setCreator("工艺信息管理平台");
 	$objProps->setLastModifiedBy("工艺科 范建鹏");
 	$objProps->setTitle("越野车装配厂 VIN码导出：Excel");
 	$objProps->setSubject("VIN码");
 	$objProps->setDescription("越野车装配厂 VIN码导出");
 	$objProps->setKeywords("越野车装配厂 VIN码");
 	$objProps->setCategory("VIN码");
 	$objRichText = new \PHPExcel_RichText(); 




 	$objExcel->setActiveSheetIndex(0);
 	$objActSheet = $objExcel->getActiveSheet();
 	//设置当前活动sheet的名称
 	$date = date("Y-m-d",time());
 	$objActSheet->setTitle('VIN码'.$date);
 	
 	//*************************************
 	//
 	//设置宽度，这个值和EXCEL里的不同，不知道是什么单位，略小于EXCEL中的宽度
 	$objActSheet->getColumnDimension('A')->setWidth(22);
 	$objActSheet->getColumnDimension('B')->setWidth(22);
 	$objActSheet->getColumnDimension('C')->setWidth(22);
 	$objActSheet->getColumnDimension('D')->setWidth(8);





 	$objActSheet->setCellValue('A1', '车型');
 	$objActSheet->setCellValue('B1', 'VIN码');
 	$objActSheet->setCellValue('C1', '任务号');
 	$objActSheet->setCellValue('D1', '数量');


 	$objStyleA = $objActSheet->getStyle('A1:D1')->getFont();
 	$objStyleA->setName('宋体');
 	$objStyleA->setSize(11);



 

$count=count($data);
$objStyleB = $objActSheet->getStyle('A2:D'.($count+2))->getFont();
$objStyleB->setName('宋体');
$objStyleB->setSize(12);




 	for($i=0;$i<$count;$i++){
 		$n=$i+2;

 
 	

$objActSheet->setCellValueExplicit('A'.$n,$data[$i][cx],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('B'.$n,$data[$i][vin],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('C'.$n,$data[$i][rwh],\PHPExcel_Cell_DataType::TYPE_STRING);
$objActSheet->setCellValueExplicit('D'.$n,$data[$i][num],\PHPExcel_Cell_DataType::TYPE_STRING);






 	}

 

 	 $styleArray = array(
 	 		'borders' => array(
 	 				'allborders' => array(
 	 						//'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
 	 						'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
 	 						//'color' => array('argb' => 'FFFF0000'),
 	 				),
 	 		),
 	 );
 	$objActSheet->getStyle('A1:D'.$n)->applyFromArray($styleArray);//这里就是画出从单元格A5到 
 	

 
 $outputFileName =iconv("utf-8", "gb2312","VIN码导出(打印格式)  ".$date).".xls";

 	header("Pragma: public");
 	header('Expires:0');





 	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 	header("Content-Type:application/force-download");
    Header('content-Type:application/vnd.ms-excel;charset=utf-8');
 	header("Content-Type:application/octet-stream");
 	header("Content-Type:application/download");
 	header("Content-Disposition: attachment;filename=$outputFileName");
 	header("Content-Transfer-Encoding:binary");

 	$objWriter->save('php://output');
 	
 	// echo $page .$pagesize;
 	exit;
 }	
}
?>